package edu.gatech.bsbmule.tests;

import static org.junit.Assert.*;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import edu.gatech.bsbmule.model.Game;
import edu.gatech.bsbmule.model.Player;
import edu.gatech.bsbmule.model.Store;

/**
 * This is the JUnit test for the buy() method in the Store class
 * Test cases:
 * Store buys 1 Food from player
 * Store buys 1 Energy from player
 * Store buys 1 Smithore from player
 * 
 * @author Melissa
 */
public class JUnit_Melissa {
	Game game;
	Store store;
	Player player;
	
	@Before
	public void init() {
		game = Game.getInstance();
		store = Store.getInstance();
		player = new Player("Bob", Color.BLUE, Player.RACE_HUMAN, 0, 5, 5, 5);
		List<Player> players = new ArrayList<Player>();
		players.add(player);
		game.setPlayers(players);
	}

	@Test
	public void testBuyFood() {
		int quantity = 1;
		int initialPlayerFood = player.getFood();
		store.buy(player, 1, quantity);
		int playerMoney = player.getMoney();
		int foodPrice = store.getPrice(1) * quantity;
		assertEquals("Player earns money", foodPrice, playerMoney);
		int updatedPlayerFood = initialPlayerFood - quantity;
		int currentPlayerFood = player.getFood();
		assertEquals("Player inventory decreased", updatedPlayerFood, currentPlayerFood);
	}
	
	@Test
	public void testBuyEnergy() {
		int quantity = 1;
		int initialPlayerEnergy = player.getEnergy();
		store.buy(player, 2, quantity);
		int playerMoney = player.getMoney();
		int foodPrice = store.getPrice(2) * quantity;
		assertEquals("Player earns money", foodPrice, playerMoney);
		int updatedPlayerEnergy = initialPlayerEnergy - quantity;
		int currentPlayerEnergy = player.getEnergy();
		assertEquals("Player inventory decreased", updatedPlayerEnergy, currentPlayerEnergy);
	}
	
	@Test
	public void testBuySmithore() {
		int quantity = 1;
		int initialPlayerSmithore = player.getSmithore();
		store.buy(player, 3, quantity);
		int playerMoney = player.getMoney();
		int foodPrice = store.getPrice(3) * quantity;
		assertEquals("Player earns money", foodPrice, playerMoney);
		int updatedPlayerSmithore = initialPlayerSmithore - quantity;
		int currentPlayerSmithore = player.getSmithore();
		assertEquals("Player inventory decreased", updatedPlayerSmithore, currentPlayerSmithore);
	}

}
